<?php

require_once 'Base.php';

class GoodsModel extends Base {
	
	public function getList($where='', $page='',$pagesize='',$order = 'id desc'){
		
		if($where) $this->where($where);
		//echo 
		
		if($pagesize) $this->limitPage($page,$pagesize);
		$this->order($order);
		//$temp=$this->select();
		//print_r($temp);
		return $this->select();
	}
	
	public function getCount($where=[]){
		//$sql = "SELECT count(*) FROM shop_goods_category where 1=1";
		$this->_db = $this->getAdapter();
    	$select = $this->_db->select();
		
		$select->from('shop_goods',"count(*) as rows");
		 foreach ($where as $key => $val) {
            if (is_int($key)) {
               
               $select->where($val);
            } else {
              
                $select->where($key, $val);
            }
	     }   

		$rs = $this->_db->fetchRow($select);
		return $rs['rows'];
	}
	
	public function getGoods($where=[]){
		
		if($where) $this->where($where);
		
		return $this->fetch();
	}
	
	public function getList2($where=''){
	
		$this->_db = $this->getAdapter();
    	$select = $this->_db->select();
    	$select->from('shop_goods');
    	
	     foreach ($where as $key => $val) {
            if (is_int($key)) {
               
               $select->where($val);
            } else {
              
                $select->where($key, $val);
            }
	     }   
    	//if($pagesize) $select->limit($pagesize,$page*$pagesize); 
    	return $this->_db->fetchAll($select);
	}
}
